#!/bin/bash
#定义脚本函数

print_usage()
{
echo "hello world!"
printf "Please enter an integer:\n"
exit 1
}

#就收用户输入的命令,-p参数后面写给用户看到的提示性消息
#read -p接受用户输入的变量
read -p "please input your number:" firstnum


#对用户的输入进行if语句的判断
#注意语法格式
#限制用户必须输入纯数字
if [ -n "`echo $firstnum|sed 's/[0-9]//g'`" ]
then
	print_usage
fi

read -p "Please input your operator:" operator

if [ "${operator}" != "+" ] && [ "${operator}" != "-" ] && [ "${operator}" != "*" ] && [ "${operator}" != "/" ]
then
	echo "只允许输入=-*/"
	exit 2
fi
#第二个参数
read -p "please input your number:" secondnum
if [ -n "`echo $secondnum|sed 's/[0-9]//g'`" ]
then
        print_usage
fi
#最后利用(())进行运算
echo "${firstnum}${operator}${secondnum} result is $((${firstnum}${operator}${secondnum}))"
